public class TestHeap {
    public int[] elem;
    public int usesize;

     public TestHeap(){
         this.elem=new int[10];
     }

     public void initElm(int[] array){
         for (int i = 0; i < array.length; i++) {
             this.elem[i]=array[i];
         }
     }

     public void creatHeap(){
         for (int parent = (this.usesize-1-1)/2; parent >=0; parent--) {
             siftDown(parent,this.usesize);

         }

     }

    private void siftDown(int parent, int usesize) {
         int child =2*parent+1;
         while (child<usesize){
             if(child+1<usesize&&elem[child]<elem[child+1]){
                 child++;

             }
             if(elem[child]>elem[parent]){
                 int tmp =elem[child];
                 elem[child]=elem[parent];
                 elem[parent]=tmp;
                 parent = child;
                 child = 2*parent+1;
             }else {
                 break;
             }
         }
    }


}
